import { defineStore } from 'pinia';
import { searchAlIByCondition } from "@/api/order";

export const useGoodsStore = defineStore('goods', {
  state: () => ({
    goods: [],
    total: 0,
    pageSize: 10,
    searchValue: "",
    currentPage: 1 // 修改为1
  }),
  actions: {
    async fetchGoods(params) {
      const res = await searchAlIByCondition(params);

      if (res.code === 0) {
        this.goods = res.data.records;
        this.total = res.data.total;
        this.currentPage = res.data.current; // 确保使用API返回的current
      }
    },
    setSearchValue(value) {
      this.searchValue = value;
    },
    setCurrentPage(pageCount) {
      this.currentPage = pageCount;
    },
  },
});
